#!/usr/bin/env/python
# -*- coding: utf-8 -*- 

# @File : Reptile.py 
# @Author : t_fengyun
# @Time : 2019/9/10 15:53 
# @desc : there is reptile


import requests
import urllib.request
from bs4 import BeautifulSoup
import os
from selenium import webdriver
import time



# url = 'http://www.6000rt.com/'
url = 'http://timgle.com/'

headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url,headers=headers)
soup = BeautifulSoup(response.content,'html.parser')
items = soup.find_all('img')
folder_path = './photo_timgle/'
if os.path.exists(folder_path)==False:
    os.mkdir(folder_path)

for index,item in enumerate(items):
    if item:
        print('爬取的连接:',item)
        html = requests.get(item.get('src'))
        img_name = folder_path + str(index+1) + '.png'
        with open(img_name,'wb') as file:
            file.write(html.content)
            file.flush()
        file.close()
        print('第%d张图片下载完成'%(index+1))
        time.sleep(1)
print('抓取完成')


